from sqlalchemy import Column, Integer, String
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from database.models.ControllerType import ControllerType
from database.models.DatabaseCommon import Base


class Controller(Base):
    __tablename__ = 'Controller'
    id = Column(Integer, primary_key=True, autoincrement=True)
    Name = Column(String, default='')
    Value = Column(String, default='0')
    HardID = Column(Integer)
    tag = Column(String)
    all = Column(String)
    capability = Column(String, default='')
    TypeID = Column(Integer, ForeignKey('ControllerType.id'))
    type = relationship('ControllerType', back_populates='controller')

    def __repr__(self):
        return "<Controller(id='%d', TypeID='%d')>" % (
            self.id, self.TypeID)


ControllerType.controller = relationship('Controller', order_by=Controller.id, back_populates='type')
